home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / MDP-80 Folder / Programs / Guess100.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-01-11  |  2.1 KB  |  92 lines  |  [TEXT/ALFA]

  1. ;
  2. ;    Guess 100 (actually 64 hex)
  3. ;
  4. ;   Computer picks a number and gives you 7 chances to guess it.
  5. ;    
  6. ;    RTK, 12-17-93
  7. ;
  8.  
  9. #include std.equ
  10.  
  11. #org 1000
  12.  
  13. #equ random 205  ;  use only the low byte
  14. #equ number 17   ;  store the number to guess here
  15. #equ count  18   ;  store the number of guesses remaining
  16.  
  17.             lda #07
  18.             sta count        ; setup count
  19.             lda #0c
  20.             jsr _cout        ; clear the screen
  21.             lda >greeting    ; get the greeting
  22.             ldx <greeting
  23.             jsr _print
  24.             jsr getNumber    ; pick a random number
  25. .prompt        lda >promptText
  26.             ldx <promptText
  27.             jsr _print
  28.             jsr _input1        ; get a number
  29.             lda >text
  30.             ldx <text
  31.             jsr _upper        ; make it uppercase
  32.             lda >text
  33.             ldx <text
  34.             jsr _number        ; make it a number
  35.             lda $02            ; get the guess (low part only)
  36.             cmp number        ; compare to the computer's number
  37.             beq winner        ; got it!
  38.             blt tooLow        ; too low
  39. .tooHigh    lda >high        ; print 'Too high!'
  40.             ldx <high
  41.             jsr _print
  42.             jmp decrement    ; reduce chances
  43. .tooLow        lda >low        ; print 'Too low!'
  44.             ldx <low
  45.             jsr _print
  46. .decrement    dec count        ; reduce count
  47.             beq loser        ; oh,oh, out of chances!
  48.             jmp prompt
  49. .loser        lda >lose        ; game over, you lose
  50.             ldx <lose
  51.             jsr _print
  52.             lda number
  53.             jsr _printHex
  54.             lda #0d
  55.             jsr _cout
  56.             jsr _cout
  57.             jmp end
  58. .winner        lda >win        ; you win!
  59.             ldx <win
  60.             jsr _print
  61. .end        rts                ; end
  62.  
  63. ;  getNumber - picks a random number
  64.  
  65. .getNumber    lda random        ; get a random number
  66.             cmp #64            ; compare to 100
  67.             bgt getNumber    ; try again until < 100
  68.             sta number        ; and save it
  69.             rts
  70.  
  71. ;  string data
  72.  
  73. .greeting    asc 'GUESS 100.  The computer is thinking of a number between 0'
  74.             asc ' and 100'
  75.             hex 0d
  76.             asc '(actually 64 since the game is in hexadecimal).'
  77.             hex 0d0d
  78.             asc 'You enter a number and the computer will tell you if it '
  79.             hex 0d
  80.             asc 'is too high, too low or correct.  You have 7 tries.'
  81.             hex 0d0d00
  82. .promptText    asc 'Your guess ? '
  83.             hex 00
  84. .high        asc 'Too high!'
  85.             hex 0d00
  86. .low        asc 'Too low!'
  87.             hex 0d00
  88. .lose        asc 'Sorry, you lose!  The number was '
  89.             hex 00
  90. .win        asc 'Correct!  You win!'
  91.             hex 0d0d00
  92.